/**
 * 
 */
package com.haizhi.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.haizhi.bean.TbPost;
import com.haizhi.bean.TbReply;
import com.haizhi.bean.TbSection;
import com.haizhi.dao.ReplyDao;
import com.haizhi.service.ReplyService;

/**
 * @author jiangjintai
 *
 */
@Service("replyService")
public class ReplyServiceImpl extends BaseServiceImpl<TbReply, Integer> implements
		ReplyService {
	@Autowired
	ReplyDao replyDao;
	/* （非 Javadoc）
	 * @see com.haizhi.service.impl.BaseServiceImpl#getDao()
	 */
	@Override
	protected JpaRepository<TbReply, Integer> getDao() {
	
		return replyDao;
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.ReplyService#findTopByTbPost(com.haizhi.bean.TbPost)
	 */
	@Override
	public TbReply findTopByTbPost(TbPost tbPost) {
		// 
		return this.replyDao.findTopByTbPost(tbPost);
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.ReplyService#findTopByTbPostAndReplyType(com.haizhi.bean.TbPost, int)
	 */
	@Override
	public TbReply findTopByTbPostAndReplyType(TbPost tbPost, int i) {
		// 
		return this.replyDao.findTopByTbPostAndReplyType(tbPost,i);
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.ReplyService#findByPostAndReplyType(com.haizhi.bean.TbPost, int, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<TbReply> findByPostAndReplyType(TbPost tbPost, int i,
			Pageable pageAble) {
		// 
		return this.replyDao.findByTbPostAndReplyType(tbPost,i,pageAble);
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.ReplyService#saveAndUpdateTbPostAndTbSection(com.haizhi.bean.TbReply)
	 */
	@Override
	public void saveAndUpdateTbPostAndTbSection(TbReply tbReply) {
		// 
		this.save(tbReply);
		TbPost tbPost  = tbReply.getTbPost();
		tbPost.setPostReplyNum(tbPost.getPostReplyNum()+1);
		TbSection tbSection = tbReply.getTbPost().getTbSection();
		tbSection.setSectionCommentNum(tbSection.getSectionCommentNum()+1);
		this.save(tbReply);
	}



}
